home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Tool Chest / Dev.CD Feb 97 TC.toast / Sample Code / Interapplication Communication / MenuScripter 4.0 / Sources / MSAEObjectsExist.c < prev    next >
Encoding:
Text File  |  1996-07-09  |  2.2 KB  |  90 lines  |  [TEXT/CWIE]

  1. // MSAEObjectsExist.c
  2. //
  3. // Original version by Jon Lansdell and Nigel Humphreys.
  4. // 4.0 and 3.1 updates by Greg Sutton.
  5. // ©Apple Computer Inc 1996, all rights reserved.
  6.  
  7. /*    
  8.     Changes for 4.0
  9.  
  10.     27-Feb-96 : GS : Added call to HandleGetData() to see if properties etc. exist
  11. */
  12.  
  13. #include "MSAEObjectsExist.h"
  14.  
  15. #include "MSAEUtils.h"
  16. #include "MSAEGetData.h"
  17.  
  18.  
  19. #pragma segment AppleEvent
  20.  
  21.  
  22. // -----------------------------------------------------------------------
  23. //    Name:         DoObjectsExist
  24. //    Purpose:    Handles the kAEDoObjectsExist AppleEvent. Basically just
  25. //                tries to resolve the object to see if it exists.
  26. // -----------------------------------------------------------------------
  27.  
  28. pascal OSErr DoObjectsExist(const AppleEvent    *theAppleEvent,
  29.                                     AppleEvent    *reply, 
  30.                                     long        handlerRefCon)
  31. {
  32. #ifdef __MWERKS__
  33.     #pragma unused (handlerRefCon)
  34. #endif
  35.  
  36.     AEDesc            directObject = {typeNull, NULL},
  37.                     directDesc = {typeNull, NULL},
  38.                     replyDesc = {typeNull, NULL},
  39.                     aDesc = {typeNull, NULL};
  40.     long            itemCount;
  41.     Boolean           exists;
  42.     OSErr             existsErr,
  43.                     err;
  44.             
  45.     err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeWildCard, &directObject);
  46.  
  47.     err = GotRequiredParams(theAppleEvent);
  48.     if (noErr != err) goto done;
  49.  
  50.     if (typeNull == directObject.descriptorType)
  51.         exists = true;        // Yes, our application does exist?????
  52.     else
  53.     {
  54.         existsErr = AEResolve(&directObject, kAEIDoMinimum, &directDesc);
  55.         
  56.         if (noErr == existsErr)
  57.         {
  58.             switch ( directDesc.descriptorType )
  59.             {
  60.                 case typeAEList:
  61.                 case typeAERecord:
  62.                     err = AECountItems( &directDesc, &itemCount );    // If not empty then
  63.                     if (noErr != err) goto done;                    //  it exists
  64.     
  65.                     exists = ( itemCount > 0 );
  66.                     break;
  67.                     
  68.                 default:
  69.                     err = HandleGetData( &directDesc, typeWildCard, &aDesc );
  70.                     exists = ( noErr == err );
  71.             }
  72.         }                                        
  73.         else
  74.             exists = false;
  75.     }
  76.     
  77.     err = AECreateDesc(typeBoolean, (Ptr)&exists, sizeof(exists), &replyDesc);
  78.     if (noErr != err) goto done;
  79.     
  80.     err = AddResultToReply(&replyDesc, reply, err);
  81.     
  82. done:
  83.     (void)AEDisposeDesc( &directObject );
  84.     (void)AEDisposeDesc( &directDesc );
  85.     (void)AEDisposeDesc( &replyDesc );
  86.     (void)AEDisposeDesc( &aDesc );
  87.         
  88.     return err;
  89. } // DoObjectsExist
  90.